#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Menu_Bar.H>
#include <FL/Fl.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Output.H>
#include <stdlib.h>
#include <iostream>
#include <string>

using namespace std;

string server = "";
string port = "";
bool 
Fl_Window* connect_win= new Fl_Window(300,200, "Testing 2");

void quit_cb(Fl_Widget *, void *) {
    exit(0);
}

void connect_but_cb( Fl_Widget* o , void*) {

    cout<<"connect_but_cb"<<endl;
   Fl_Button* b=(Fl_Button*)o;
   Fl_Input* iw_server  = (Fl_Input*) b -> parent() -> child(2);
   Fl_Input* iw_port    = (Fl_Input*) b -> parent() -> child(3);
   //Fl_Output* ow = (Fl_Output*) b -> parent() -> child(3);
   //ow->value( iw->value() );

   server   = iw_server->value();
   port     = iw_port->value();

   //cout<<"Server = "<<server<<endl;
   //cout<<"Port   = "<<port<<endl;

   connect_win->hide();
}

void window_cb(Fl_Widget* o, void*)
{
    ((Fl_Window*)o)->hide();
}


void connect_cb(Fl_Widget *w, void*)
{
    cout<<"Connect_cb"<<endl;

    connect_win->begin();      
    Fl_Button*  connect = new Fl_Button( 10, 150, 70, 30, "C&onnect"); //child 0   : 1st widget
    Fl_Button* close = new Fl_Button(100, 150, 70, 30, "&Quit"); //child 1    : 2nd widget
    Fl_Input*       server= new Fl_Input(50, 50, 140, 30, "Server");//child 2 : 3rd widget
    Fl_Input*       port  = new Fl_Input(50, 100, 140, 30, "Port"); //child 3   : 4th widget 
    //Fl_Output*    out = new Fl_Output(50, 100, 140, 30, "Out"); 
    connect_win->end();
    connect->callback(  connect_but_cb );
    close->callback( quit_cb );
    connect_win->show();
}

int main()
{
    Fl_Window *win = new Fl_Window(400,400);
    Fl_Menu_Bar *menu = new Fl_Menu_Bar(0,0,400,25);
    menu->add("File/Close",   FL_CTRL+'q', quit_cb);
    menu->add("Server/Connect", FL_CTRL+'c', connect_cb);
    menu->add("Edit/Submenu/Aaa");
    menu->add("Edit/Submenu/Bbb");
    win->end();
    win->show();
    return(Fl::run());
}